class PasswordsController < ApplicationController
  layout "login"
  
  skip_before_filter :check_user_logged, 
                     :redirect_if_not_active,
                     :set_time_zone
  def new
  end
  
  def create
    @user = User.find_by_email(params[:email])
    
    if @user
      password = @user.generate_password
      @user.password = @user.password_confirmation = password
      if @user.save
        #Delayed::Job.enqueue PasswordReminderMailerJob.new(@user.id, password)
        UserMailer.deliver_password_reminder_email(@user, password)
        flash[:notice] = I18n.t :reseted_password, :scope => [:authentication, :messages, :success]
        redirect_to login_url and return
      else
        flash[:error] = I18n.t :reseted_password, :scope => [:authentication, :messages, :error]
        render :action => "new"
      end
    else
      flash[:error] = I18n.t :email_not_found, :scope => [:authentication, :messages, :error]
      render :action => "new"
    end
  end

end
